<template>
  <div class="TeachingVideos" v-if="tabsList?.length > 0">
    <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
      <el-tab-pane
        v-for="(item, index) in tabsList"
        :key="index"
        :label="item.label"
        :name="index"
      >
      </el-tab-pane>
    </el-tabs>
    <Video
      v-if="activeTab.type === 'mp4' && activeTab.url"
      :url="activeTab.url"
    ></Video>

    <XnFilePreview
      v-if="activeTab.type !== 'mp4' && activeTab.url"
      :src="activeTab.url"
      :file-type="activeTab.type"
    />
  </div>
</template>

<script setup>
import { ref, h } from "vue";
import Video from "../common/Video.vue";
import XnFilePreview from "../common/FilePreview.vue";
import { parseUrlFileType } from "../../utils/aes";
const tabsList = ref([
  // { label: "视频一", name: "first" },
  // { label: "视频二", name: "second" },
  // { label: "课件", name: "third" },
]);
const activeTab = ref({});
const activeName = ref(0);
const handleClick = (tab, event) => {
  activeName.value = tab.props.name;
  activeTab.value = tabsList.value[activeName.value];
};
const props = defineProps({
  data: {
    type: Object,
    default: () => {},
  },
  courseware: {
    type: String,
    default: "",
  },
});
// 数字转中文
const numToChinese = (num) => {
  const chnNumChar = [
    "零",
    "一",
    "二",
    "三",
    "四",
    "五",
    "六",
    "七",
    "八",
    "九",
  ];
  return chnNumChar[num];
};
const setTabsList = () => {
  let list = props.data?.map((item, i) => {
    const urlDto = parseUrlFileType(item);
    return {
      label: "视频" + numToChinese(i + 1),
      ...urlDto,
    };
  });
  if (props.courseware) {
    const urlDto = parseUrlFileType(props.courseware);
    list.push({
      label: "课件",
      ...urlDto,
    });
  }
  tabsList.value = list;
  activeTab.value = tabsList.value?.[activeName.value];
};
onMounted(() => {
  setTabsList();
});
watch(
  () => props,
  (newVal) => {
    setTabsList();
  },
  { deep: true }
);
</script>

<style lang="less" scoped>
.TeachingVideos {
  // padding: 20px;
  .demo-tabs {
    :deep(.el-tabs__header) {
      .el-tabs__item {
        height: 40px;
        line-height: 40px;
        font-weight: bold;
        padding: 10px 20px;
      }
    }
    :deep(.el-tabs__content) {
      padding: 10px 0;
    }
    :deep(.el-tabs__nav-wrap::after) {
      height: 1px;
    }
    :deep(.el-tabs__item.is-active) {
      color: #217300;
    }
    :deep(.el-tabs__item:hover) {
      color: #217300;
    }
    :deep(.el-tabs__active-bar) {
      background-color: #217300;
    }
    :deep(.el-tabs__nav-wrap:after) {
      display: none;
    }
  }
}
</style>
